import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      appBar: AppBar(
        title: const Text("Roll Widget Demo"),
      ),
      body: PageViewWidget(),
    ),
  ));
}

class PageViewWidget extends StatefulWidget {

  @override
  _PageViewWidgetState createState() => _PageViewWidgetState();

}

class _PageViewWidgetState extends State<PageViewWidget> {


  @override
  Widget build(BuildContext context) {
    var children = <Widget>[];
    // 生成 6 个 Tab 页
    for (int i = 0; i < 6; ++i) {
      children.add( Page( text: '$i'));
    }

    return PageView(
      scrollDirection: Axis.vertical, // 滑动方向为垂直方向
      children: children,
      allowImplicitScrolling: true,  //缓存前后两页
    );
  }
}


class Page extends StatefulWidget{

  const Page({Key?key, required this.text}):super(key:key);

  final String text;

  @override
  State<Page> createState() {
    return PageSate();
  }
}

class PageSate extends State<Page>{
  @override
  Widget build(BuildContext context) {
    print("build ${widget.text}");
    return Center(child: Text(widget.text,textScaleFactor: 5,));
  }

}